public class Test02 {

    public void sortColors(int[] nums) {
        int left = -1,i = 0;
        int right = nums.length;
        while (i < right){
            if (nums[i] == 0){
                //进行交换
                swap(nums,++left,i++);
            }else if (nums[i] == 2){
                swap(nums,--right,i);
            }else {
                i++;
            }
        }
    }

    //交换函数
    private void swap(int[] array,int i, int j) {
        int tmp = array[i];
        array[i] = array[j];
        array[j] = tmp;
    }



    public static void main(String[] args) {

    }
}
